package com.maixin.code.action;

import java.util.ArrayList;
import java.util.List;

import com.maixin.code.base.BaseAction;
import com.maixin.code.entity.DataDictionary;
import com.maixin.code.service.DataDictionaryService;
import com.maixin.code.utils.Json2JavaUtils;
/**
 * 数据字典Action
 * @author SJ
 *
 */
public class DataDictionaryAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private DataDictionaryService dataDicSer;
	
	private DataDictionary dataDict;
	private List<DataDictionary> list;
	private String content;
	private Integer cnt;
	
	/**
	 * 查询数据字典分页数据
	 * @return
	 * @throws Exception
	 */
	public String selAllDataDic() throws Exception{
		list = dataDicSer.getBaseDao().findAll(DataDictionary.class, start, limit);	
		cnt = dataDicSer.getBaseDao().findTabCnt(DataDictionary.class);
		return SUCCESS;
	}
	
	/**
	 * 查询父节点数据
	 * @return
	 */
	public String findPerantDict(){
		list = dataDicSer.findPerantDict();
		return SUCCESS;
	}

	
	/**
	 * 添加或修改数据
	 * @return
	 */
	public String addDataDic(){
		try{
			List<?>  l = Json2JavaUtils.json2Java(content, DataDictionary.class);
			list = new ArrayList<DataDictionary>();
			for (int i = 0; i < l.size(); i++) {
				DataDictionary d_list = (DataDictionary) l.get(i);
				if(null == d_list.getId() || "".equals(d_list.getId())){
					dataDict = dataDicSer.getBaseDao().save(d_list);
				}else{
					dataDict = dataDicSer.getBaseDao().update(d_list);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 删除数据
	 * @return
	 * @throws Exception
	 */
	public String delDataDic()throws Exception{
		dataDicSer.getBaseDao().delete(dataDict);
		return SUCCESS;
	}
	public DataDictionaryService getDataDicSer() {
		return dataDicSer;
	}
	
	public void setDataDicSer(DataDictionaryService dataDicSer) {
		this.dataDicSer = dataDicSer;
	}

	public List<DataDictionary> getList() {
		return list;
	}

	public void setList(List<DataDictionary> list) {
		this.list = list;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

//	public DATADictionary1 getDataDict() {
//		return dataDict;
//	}
//
//	public void setDataDict(DATADictionary1 dataDict) {
//		this.dataDict = dataDict;
//	}

	

	public Integer getCnt() {
		return cnt;
	}

	public void setCnt(Integer cnt) {
		this.cnt = cnt;
	}

	public DataDictionary getDataDict() {
		return dataDict;
	}

	public void setDataDict(DataDictionary dataDict) {
		this.dataDict = dataDict;
	}
	
	
}
